import simpleTable from "@/mixins/SimpleTable";
import common from "@/mixins/common";
import qs from "qs";
import { getToken } from "@/utils/auth";
import workManagement from "@/api/workManagement/index";
import eventBus from '@/utils/eventBus'
export default {
  name:"ExtendTable",
  props: {
    params:{
      type:Object,
      default:()=>{
        return {}
      }
    },
  },
  data() {
    return {
      formData:{
        dept:undefined,
        starttime:undefined,
        endtime:undefined,
        starttime2:undefined,
        endtime2:undefined,
        search_value:undefined,
        is_draft:undefined
      },
    }
  },
  mixins: [simpleTable,common],
  computed: {
    isAll() {
      return this.params.category=='all'
    },
    isDraft() {
      return this.params.category=='draft'
    },
    isTodo() {
      return this.params.category=='duty'
    },
    isYiban() {
      return this.params.category=='relation'
    },
    isFaqi() {
      return this.params.category=='owner'
    },
    isDaiyue() {
      return this.params.category == 'daiyue'
    },
    isYiyue() {
      return this.params.category == 'yiyue'
    },
    isDelete(){
      return this.isDraft||this.params.category=='all'
    }
  },
  watch: {},
  created() {
  },
  mounted() {
  },
  methods: {
    toPrint(UUID){
      window.open(
        `${process.env.VUE_APP_BASE_API}/api/${this.interfaceUrl}/${UUID}/print/?token=${getToken()}`
      );
    },
    toExport(){
      window.open(
        `${process.env.VUE_APP_BASE_API}/api/${this.interfaceUrl}/export/?${qs.stringify(this.formData)}&token=${getToken()}`
      );
    },
    handleSelect(item) {
    },
    toDetail(row){
      if(this.isDraft || row.is_edit&&this.isTodo){
        this.toEdit(row)
      }else if(this.isTodo){
        this.toHandle(row)
      }
      else{
        this.toView(row)
      }
    },
    toEdit(row){
      this.$emit("showDialog",row,"edit")
    },
    toHandle(row){
      this.$emit("showDialog",row,"handle")
    },
    toView(row){
      this.$emit("showDialog",row,"view")
    },
    handleAdd(row) {
      let params = row?row:{}
      this.$emit("showDialog",params,"add")
    },
    query(queryData) {
      this.formData.search_value = queryData
      this.$refs["myTable"].searchList(this.formData);
    },
    getList() {
      this.$refs["myTable"].searchList();
    },
    toCancel(row){
      this.$confirm("您确认将此审批单取消到我的草稿并通知当前待办人？此操作将抹去审批流程日志，请谨慎操作！是否取消？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        workManagement.setTicketsCancel(row.ticket).then(res=>{
          this.msgSuccess(res.msg)
          this.query();
        })
      });
    },
    setTicketsRetreat(row){
      this.$confirm("您确认撤回将此审批单？此操作将保留审批流程日志，请谨慎操作！是否撤回？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        workManagement.setTicketsRecall(row.ticket).then(res=>{
          this.msgSuccess(res.msg)
          eventBus.$emit('setActiveName', 'daiban')
        })
      });
    }
  }
}
